package com.ak.routedirect;

import com.ak.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.Random;

public class Provider {
    public static void main(String[] args) throws IOException {
        Connection connection= RabbitMQUtils.getConnection();
        Channel channel=connection.createChannel();
        // 参数一：为交换机名称，参数二：fanout 为交换机
        channel.exchangeDeclare("log_router","direct");
        String []routeKey={"error","info","waring","debug"};

        // 发送信息
        for(int i=0;i<10;i++){
            int temp=new Random().nextInt(100)%4;
            channel.basicPublish("log_router",routeKey[temp],null,("发送的信息为 "+routeKey[temp]).getBytes());
        }
        RabbitMQUtils.closeConnectionAndChanel(channel,connection);

    }
}
